Avoid use of assert.ok() when there is clearly a comparison being made.
Previously the result of the comparison was implicit in match() returning
an array with a match instead of null.
Change this to instead extract the value and let QUnit see the comparison.
In case of a failure, the actual and expected values will now be reported.
Change-Id: Ieaea090469efba24f6f5bf44f5c8e238b017275f
return sequence( bodies );
}
return sequence( bodies );
}
+ // Utility to make inline use with an assert easier
+ function match( text, pattern ) {
+ var m = text.match( pattern );
+ return m && m[ 1 ] || null;
+ }
+
QUnit.test( 'get()', function ( assert ) {
var api = new mw.Api();
QUnit.test( 'get()', function ( assert ) {
var api = new mw.Api();
var api = new mw.Api();
this.server.respond( function ( request ) {
var api = new mw.Api();
this.server.respond( function ( request ) {
- assert.ok( request.url.match( /test=foo%7Cbar%7Cbaz/ ), 'Pipe-separated value was submitted' );
+ assert.equal( match( request.url, /test=([^&]+)/ ), 'foo%7Cbar%7Cbaz', 'Pipe-separated value was submitted' );
request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
} );
request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
} );
var api = new mw.Api();
this.server.respond( function ( request ) {
var api = new mw.Api();
this.server.respond( function ( request ) {
- assert.ok( request.url.match( /test=Foo%7CBar/ ), 'Pipe-separated value was submitted' );
+ assert.equal( match( request.url, /test=([^&]+)/ ), 'Foo%7CBar', 'Pipe-separated value was submitted' );
request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
} );
request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
} );
var api = new mw.Api();
this.server.respond( function ( request ) {
var api = new mw.Api();
this.server.respond( function ( request ) {
- assert.ok( request.url.match( /test=true%7Cfalse%7C%7C%7C0%7C1%2E2/ ), 'Pipe-separated value was submitted: ' + request.url );
+ assert.equal( match( request.url, /test=([^&]+)/ ), 'true%7Cfalse%7C%7C%7C0%7C1%2E2', 'Pipe-separated value was submitted' );
request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
} );
request.respond( 200, { 'Content-Type': 'application/json' }, '[]' );
} );